package com.game.scene
{
	import com.game.GameBase;
	import com.game.render.RenderData;
	import com.utils.Val;

	/**
	 * 游戏中场景对象基类
	 * 角色,NPC,怪物,掉落物品
	 * @author hyy
	 *
	 */
	public class SceneObject extends GameBase
	{
		public var mapX : Number;

		public var mapY : Number;

		protected var _alpha : Number = 1;

		protected var _visible : Boolean = true;

		protected var mainRender : RenderData;

		protected var zIndex : int;

		/**
		 * -1代表需要自动销毁
		 * @param id
		 *
		 */
		public function SceneObject(id : int, zIndex : int = Val.LAYER_TOP)
		{
			this.zIndex = zIndex;
			super(id);
		}

		override protected function init() : void
		{
			mainRender = new RenderData();
			mainRender.zIndex = zIndex;
			mainRender.addShow();
		}

		override public function update(elapsedTime : uint) : void
		{
			mainRender.x = mapX;
			mainRender.y = mapY;
			super.update(elapsedTime);
		}

		public function addRender(render : RenderData) : void
		{
			mainRender.addChild(render);
		}

		public function removeRender(render : RenderData) : void
		{
			mainRender.removeChild(render);
		}

		/**
		 * 透明度
		 */
		public function get alpha() : Number
		{
			return _alpha;
		}

		/**
		 * @private
		 */
		public function set alpha(value : Number) : void
		{
			_alpha = value;

			if (mainRender)
				mainRender.alpha = value;
		}

		/**
		 * 是否可见
		 */
		public function get visible() : Boolean
		{
			return _visible;
		}

		/**
		 * @private
		 */
		public function set visible(value : Boolean) : void
		{
			_visible = value;

			if (mainRender)
				mainRender.visible = value;
		}

		override public function destroy() : void
		{
			super.destroy();

			if (mainRender)
			{
				mainRender.destory();
				mainRender = null;
			}
		}

	}
}